<?php

require_once( $_SERVER['DOCUMENT_ROOT'].'/libs/smarty.inc' );

require_once( $_SERVER['DOCUMENT_ROOT'].'/libs/smt_variables.php' );

require_once( $_SERVER['DOCUMENT_ROOT'].'/libs/Class_DB.php' );

require_once( $_SERVER['DOCUMENT_ROOT'].'/libs/Class_ERROR.php' );

require_once( $_SERVER['DOCUMENT_ROOT'].'/libs/login.inc.php' );



if( !in_array( "M", $_SESSION['ADMIN_LOGIN']['AUTH_CD'] ) ) exit;


if( $_SERVER['REQUEST_METHOD'] == 'GET' ){

	if( isset($_GET['price_no']) && $_GET['price_no'] != '' ){		

		if( is_numeric( $_GET['price_no'] ) ){
			$db = new Class_DB;
			if($_GET['mode'] == 'select'){
				//SQLクエリー
				$sql = "SELECT * FROM p_consumer_detail where price_no = '".$_GET['price_no']."'";	
				
				$res = $db->query($sql);
	
					
				while( $row = mysql_fetch_array($res,MYSQL_ASSOC) ){				
					
					$pricelist[] = $row;				
					
				}		
			}	
		}
	}
}elseif( $_SERVER['REQUEST_METHOD'] == 'POST' ){

	if( isset($_POST['price_no']) && $_POST['price_no'] != '' ){		
		
		if( is_numeric( $_POST['price_no'] ) ){
			
			$db = new Class_DB;
			if($_POST['mode'] == 'update'){
				$price_no = $_POST['price_no'];
				$consumer_id = $_POST['consumer_id'];
				$m_date = $_POST['m_date'];
				$pro_name = $_POST['pro_name'];				
				$category = $_POST['category'];
				$producer = $_POST['producer'];
				$examiner = $_POST['examiner'];
				$e_date = $_POST['e_date'];
				$status = $_POST['status'];
				$remark = $_POST['remark'];
				
				
				//アップデート
				$date = date('Y/m/d G:i:s');
				
				//SQLクエリー
				$u_sql = "UPDATE p_consumer_detail SET ";
				
				$sql = "SELECT m_date FROM p_consumer_detail where price_no = '".$_POST['price_no']."'";
				$res = $db->query( $sql );	
				$row = mysql_fetch_array($res,MYSQL_ASSOC);
				
				if($m_date != null){
					$u_sql = $u_sql." m_date='".$m_date."',";
				}else{
					$u_sql = $u_sql." m_date='".$row['m_date']."',";
				}
				
				$u_sql = $u_sql."pro_name='".$pro_name.
								"',category='".$category.
								"',producer='".$producer.
								"',examiner='".$examiner."',";
				
				
				if($e_date != null){
					$u_sql = $u_sql."e_date='".$e_date."',";
				}else{
					$u_sql = $u_sql."e_date='".$date."',";
				}
				
				$u_sql = $u_sql."status='".$status."',remark='".$remark."'  WHERE price_no = '".$_POST['price_no']."'";
				
				$db->query( $u_sql );	
				
				header("Location:./consumer_index.php");
			}
		}
	}
}




$menu_html = file_get_contents( $_SERVER['DOCUMENT_ROOT'].'/templates/web-admin/menu.html' );

$smarty->assign('menu_html', $menu_html);

$smarty->assign('pricelist', $pricelist);

$smarty->display('web-admin/update_price_result.html');


?>